<template>
  <el-container class="home-page">

    <el-header class="header">
      <h1>欢迎使用惊喜一餐！</h1>
      <p>发现属于你的美食惊喜</p>
    </el-header>


    <el-main>
      <el-carousel indicator-position="outside" height="450px" autoplay interval="4000">
        <el-carousel-item v-for="(image, index) in carouselImages" :key="index">
          <div class="carousel-wrapper">
            <img :src="image" class="carousel-image" />
            <div class="carousel-overlay">
              <h2 class="carousel-text">探索世界美食</h2>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>


      <h2 class="section-title">推荐餐厅</h2>


      <el-row :gutter="20">
        <el-col :span="8" v-for="restaurant in recommendedRestaurants" :key="restaurant.id">
          <el-card shadow="hover" class="restaurant-card">
            <img :src="restaurant.image" alt="餐厅图片" class="restaurant-image" />
            <div class="restaurant-info">
              <h3>{{ restaurant.name }}</h3>
              <p>评分：{{ restaurant.rating }}</p>
              <el-button
                  type="primary"
                  class="details-button"
                  @click="goToDetails(restaurant.id)"
              >
                查看详情
              </el-button>
            </div>
          </el-card>
        </el-col>
      </el-row>

      <!-- 查看更多按钮 -->
      <div class="more-button-container">
        <el-button type="success" size="large" class="more-button" @click="viewMore">
          查看更多餐厅推荐
        </el-button>
      </div>
    </el-main>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      carouselImages: [
        "./src/assets/cokeming1.png",
        "./src/assets/cokeming2.png",
        "./src/assets/cokeming3.png",
      ],
      recommendedRestaurants: [
        {id: 1, name: "付飞扬的火锅店", rating: 4.8, image: './src/assets/mainimg1.png'},
        {id: 2, name: "付飞扬的烤肉店", rating: 4.7, image: "./src/assets/mainimg2.png"},
        {id: 3, name: "付飞扬的拉面馆", rating: 5.0, image: "./src/assets/mainimg3.png"},
      ],
    };
  },
  methods: {
    goToDetails(id) {
      this.$router.push(`/restaurant/${id}`);
    },
    viewMore() {
      this.$router.push("/restaurants");
    },
  },
};
</script>

<style scoped>

.home-page {
  background: linear-gradient(to bottom, #f5f5f5, #ffffff);
  font-family: 'Arial', sans-serif;
}

.header {
  height: auto !important; 
  min-height: 150px; /* 设置最小高度以确保有足够空间显示文本 */
  text-align: center;
  padding: 20px 0;
  color: #333;
  /* 清除背景颜色以便于查看文本 */
  background-color: transparent !important; 
}

.header h1 {
  font-size: 2.5em;
  margin-bottom: 10px;
  color: #42a5f5;
}

.header p {
  font-size: 1.2em;
  color: #666;
}

/* 轮播图样式 */
.carousel-wrapper {
  position: relative;
}

.carousel-image {
  width: 100%;
  height: 450px;
  object-fit: cover;
  border-radius: 10px;
}

.carousel-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.5), transparent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-text {
  color: #42a5f5;
  font-size: 2.5em;
  font-weight: bold;
  text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.8);
}


.section-title {
  margin: 30px 0 10px;
  text-align: center;
  font-size: 1.8em;
  color: #333;
}


.restaurant-card {
  text-align: center;
  border-radius: 10px;
  overflow: hidden;
  transition: transform 0.3s ease;
}

.restaurant-card:hover {
  transform: translateY(-10px);
}

.restaurant-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 10px 10px 0 0;
}

.restaurant-info {
  padding: 10px;
}

.details-button {
  background: linear-gradient(to right, #42a5f5, #478ed1);
  border: none;
  margin-top: 10px;
  color: #fff;
}

.details-button:hover {
  background: linear-gradient(to right, #478ed1, #42a5f5);
}


.more-button-container {
  text-align: center;
  margin-top: 20px;
}

.more-button {
  background: linear-gradient(to right, #66bb6a, #43a047);
  border: none;
  color: white;
  padding: 10px 20px;
  border-radius: 30px;
}

.more-button:hover {
  background: linear-gradient(to right, #43a047, #66bb6a);
}
</style>
